var x=y=0;
	$(function(){
	   easyloader.base = 'js/tools/easyui/';
	   using("locale/easyui-lang-zh_CN.js",function(){
	      var columns=[[
	                              {field: 'id',title: '标识',width: 80,align: 'center',hidden:true},
						          {field: 'name',title: '栏目名称',width: 80,align: 'center'},
								  {field: 'isNav',title: '是否显示在主导航',width: 120,align: 'center'},
						          {field: 'url',title: '链接地址',width: 80,align: 'center'}, 
						          {field: 'sort',title: '排序',width: 80,align: 'center',editor:'numberbox'}, 
								  {field: 'modify',title: '修改',width:80,align: 'center'}
							 ]];
	         createDateGrid(columns,'websiteConfiger!websiteColumnList.action','',false,560);
	   });
	   $("#dialog").dialog();
	  $(document).mousemove(function(e){
		var e=e||event;
		 x=e.clientX+15;
		 y=e.clientY+10;
	})
	  
	});
	function sort(id,sort)
	{
	 var param={"websiteColumn.sort":sort,"websiteColumn.id":id};
	   $.getJSON("ajax/website!columnSort.action",param,function(data){
								  	
		});
	}
	
	//添加栏目
	function add()
	{
		$('#dialog').dialog('setTitle','添加栏目');
		$("#add").show();
		$("#modify").hide();
	
		$("#name").val('');
	   $("#url").val('');
	   
	   	$("input[type='checkbox']").attr("checked",false);
	   
	   $("#isList").attr("disabled","");
	   $("#sort").val(1);
		$('#dialog').dialog('open');
	}
	function addColumn()
	{
	
	   var name=$.trim($("#name").val());
	   var url=$.trim($("#url").val());
	   var isNav=($("input[type='checkbox']").attr("checked")==true)?1:0;
	   var isList=$("#isList").val();
	   var sort=$("#sort").val();
	   if(name.length<1||name.length>21)
	   {
	     $("#name").css({"border": "2px solid red"});
	      alert("栏目名称的长度为1~20");
	      return false;
	   }
	  
		var reg=/^[a-zA-Z0-9_]+$/ ;
	   if(url.length<1||url.length>30)
	   {
	     $("#url").css({"border": "2px solid red"});
	      alert("URL的长度为1~30");
	      return false;
	   }
	   if(!reg.test(url) )
			{
			   alert("只能由英文字母、数字或下划线组成");
			  $("#url").css({"border": "2px solid red"});
			  return false;
			}
			reg=/^[0-9]+$/;
		if(!reg.test(sort))
		{
			 alert("必需输入数字");
			  $("#sort").css({"border": "2px solid red"});
			  return false;
		}
	   $("#name,#url,#sort").css("border");
	   var param={};
	       param["websiteColumns.name"]=encodeURI(name);
	       param["websiteColumns.url"]=url;
	       param["websiteColumns.isNav"]=isNav;
	       param["websiteColumns.isList"]=isList;
	       param["websiteColumns.sort"]=sort;
	       var url="websiteConfiger!addWebsiteColumn.action";
	    $.getJSON(url,param,function(data){
	          if(data.info)
	          {
			  	$("#dataGrid").datagrid("reload");
				$('#dialog').dialog('close');
	            alert("添加成功");
	          }else
	          {
	            alert("已经存在该URL，请用其它的!");
	          }
	       });
	}
	var wid;
	//修改栏目
	function modify(id)
	{
		wid=id;
		$("#add").hide();
		$("#modify").show();
	   $.getJSON("websiteConfiger!findWebsiteColumn.action",{"websiteColumns.id":id},function(data){
		   	$("#name").val(data.name);
		   $("#url").val(data.url);
		   if(data.isNav==0)
		   {
		   	$("input[type='checkbox']").attr("checked",false);
		   }else
		   {
		   	$("input[type='checkbox']").attr("checked",true);
		   }
		   $("#isList").val(data.isList);
		   $("#isList").attr("disabled","disabled");
		   $("#sort").val(data.sort);
		   $('#dialog').dialog('setTitle',"修改栏目");
		   	$('#dialog').dialog('open');
	   	
	   });
		
		
	}
   function modifyColumn()
	{
	   var name=$.trim($("#name").val());
	   var url=$.trim($("#url").val());
	   var isNav=($("input[type='checkbox']").attr("checked")==true)?1:0;
	   var isList=$("#isList").val();
	   var sort=$("#sort").val();
	   if(name.length<1||name.length>21)
	   {
	     $("#name").css({"border": "2px solid red"});
	      alert("栏目名称的长度为1~20");
	      return false;
	   }
	  
		var reg=/^[a-zA-Z0-9_]+$/ ;
	   if(url.length<1||url.length>30)
	   {
	     $("#url").css({"border": "2px solid red"});
	      alert("URL的长度为1~30");
	      return false;
	   }
	   if(!reg.test(url) )
			{
			   alert("只能由英文字母、数字或下划线组成");
			  $("#url").css({"border": "2px solid red"});
			  return false;
			}
			reg=/^[0-9]+$/;
		if(!reg.test(sort))
		{
			 alert("必需输入数字");
			  $("#sort").css({"border": "2px solid red"});
			  return false;
		}
	   $("#name,#url,#sort").css("border");
	   var param={};
	       param["websiteColumns.id"]=wid;
	       param["websiteColumns.name"]=encodeURI(name);
	       param["websiteColumns.url"]=url;
	       param["websiteColumns.isNav"]=isNav;
	       param["websiteColumns.isList"]=isList;
	       param["websiteColumns.sort"]=sort;
	       var url="websiteConfiger!modifyWebsiteColumn.action";
	    $.getJSON(url,param,function(data){
	          if(data.info)
	          {
			  	$("#dataGrid").datagrid("reload");
				$('#dialog').dialog('close');
	            alert("修改成功");
	          }else
	          {
	            alert("已经存在该URL，请用其它的!");
	          }
	       });
	}